package com.iot.ic.modules.task;

import com.iot.ic.common.utils.DateUtils;
import com.iot.ic.modules.model.PatientCase;
import com.iot.ic.modules.model.User;
import com.iot.ic.modules.service.PatientCaseService;
import com.iot.ic.modules.util.MiPushUtils;
import com.xiaomi.xmpush.server.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 定时任务
 */
@Component("caseTask")
public class CaseTask {
    @Autowired
    private PatientCaseService patientCaseService;

    /**
     * 扫描病例
     */
    @Scheduled(fixedRate = 30000)
    public void job1() {
        try {
            List<PatientCase> list = patientCaseService.findNoticeCase();
            if(list.size()>0){
                PatientCase pc = list.get(0);
                User user = list.get(0).getUser();
                Result result = MiPushUtils.send(pc.getCaseNote(),user.getTrueName(),user.getMobile(),user.readmRegId());
                System.out.println( "MessageId: " + result.getMessageId()
                        + " ErrorCode: " + result.getErrorCode().getDescription()
                        + " Reason: " + result.getReason());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
